package com.luokun.vue_shop.controller;

import com.luokun.vue_shop.api.Json;
import com.luokun.vue_shop.api.Result;
import com.luokun.vue_shop.entity.SpRole;
import com.luokun.vue_shop.service.ISpRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@CrossOrigin(origins="*")
@RestController
@Slf4j
@RequestMapping("/SpRole")
public class SpRoleController {

    @Autowired
    ISpRoleService iSpRoleService;

    @GetMapping("/roles")
    public void Roles(HttpServletResponse response) throws Exception {
        List<SpRole> list = iSpRoleService.list();
        if (list.isEmpty()) {
            Result result = new Result(true, 7000, "没有数据");
            Json.toJson(result, response);
        } else {
            Result result = new Result(true, 200, "角色列表数据加载成功", list);
            Json.toJson(result, response);
        }
    }
}
